package com.daekwang.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.daekwang.domain.BoardVO;
import com.daekwang.domain.Result;
import com.daekwang.service.BoardService;
import com.google.gson.Gson;

@Controller
public class BoardAction {
	
	static Logger logger = Logger.getLogger(BoardAction.class);
	
	private BoardService service;
	
	public void setService(BoardService service) {
		this.service = service;
	}
	
	@RequestMapping(value = "board.action", params = "method=getContentList") 
	@ResponseBody
	public Result getContentList(BoardVO vo) {
		
		Result result = new Result();
		result.setSuccess(false);
		
		Map<String, Object> paging = new HashMap<String, Object>();
		
		int totalRows = service.countContent(vo);
		//시작번호, 보여줄 목록수
		List<BoardVO> list = service.getContentList(vo);
		
		paging.put("total_rows", totalRows);
		paging.put("content_list", list);
		
		result.setJsonString(new Gson().toJson(paging));
		
		return result;
	}
}
